﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace TowerDefenseXNA
{
    class Animations : Objeto//Herança extends 
    {
        SoundEffect efeitoSonoro;
        public animacao animation;

        public int jogador;
        animacao animacao_atual;

        double lastUsed = 0;

        GameTime time;

        public Animations(Texture2D imagem, GameWindow Window, SoundEffect efeitoSonoro)
            : base(imagem, Window)
        {
            posicao = new Vector2(50, 50);
            velocidade = new Vector2(3, 3);
            this.efeitoSonoro = efeitoSonoro;

            lastUsed = 0;
            animation = new animacao();
            animation.qtd_quadros = 1;
            animation.quadros_seg = 1;
            animation.Y = 0;
            animation.quadro_X = imagem.Width;
            animation.quadro_Y = imagem.Height;

            animacao_atual = animation;

            colisao = new Rectangle((int)posicao.X, (int)posicao.Y, animacao_atual.quadro_X, animacao_atual.quadro_Y);

        }

      
        //sobrecarregamento ou overload
        public override void Update(GameTime gameTime)
        { }

        public void Update(GameTime gameTime, KeyboardState teclado_atual, KeyboardState teclado_anterior, MouseState mouse_atual, MouseState mouse_anterior, Torre player)
        {

            time = gameTime;

            if (this.visivel)
            {
                if (lastUsed <= 0)
                {
                    lastUsed = gameTime.TotalGameTime.TotalSeconds;
                }
                else
                {
                    if ((gameTime.TotalGameTime.TotalSeconds - lastUsed) >= 0.2)
                    {
                        this.visivel = false;
                        lastUsed = 0;
                    }
                        

                }
            }


            switch (player.direcao)
            {
                case 0:
                    {
                        posicao.X = (int)(player.Posicao.X + (player.width/5));
                        posicao.Y = (int)(player.Posicao.Y );
                    }
                    break;
                case 1:
                    {
                        posicao.X = (int)(player.Posicao.X + (player.width));
                        posicao.Y = (int)(player.Posicao.Y + (player.height/2));
                    }
                    break;
                case 2:
                    {
                        posicao.X = (int)(player.Posicao.X + (player.width/5));
                        posicao.Y = (int)(player.Posicao.Y + (player.height));
                    }
                    break;
                case 3:
                    {
                        posicao.X = (int)(player.Posicao.X - (player.width/2));
                        posicao.Y = (int)(player.Posicao.Y + (player.height/2));
                    }
                    break;
                default:
                    break;
            }

            

            colisao.X = (int)posicao.X;
            colisao.Y = (int)posicao.Y;
            
            colisao.Width = animacao_atual.quadro_X;
            colisao.Height = animacao_atual.quadro_Y;

     
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            base.Draw(gameTime, spriteBatch, animacao_atual);
        }


    }
}
